package org.n.shop.controller;

import lombok.AllArgsConstructor;
import org.n.shop.annotation.RequiresLogin;
import org.n.shop.domain.entity.ShoppingCart;
import org.n.shop.result.RestResult;
import org.n.shop.service.ShoppingCartService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shopping/cart")
@AllArgsConstructor
public class ShoppingCartController {
    private ShoppingCartService shoppingCartService;

    @RequiresLogin
    @RequestMapping("/add")
    public RestResult add(@RequestHeader("authorization") String authorization, @RequestBody ShoppingCart shoppingCart) {
        return shoppingCartService.add(authorization, shoppingCart);
    }

    @RequiresLogin
    @RequestMapping("/all")
    public RestResult all(@RequestHeader("authorization") String authorization) {
        return shoppingCartService.all(authorization);
    }

    @RequiresLogin
    @RequestMapping("/update/number")
    public RestResult updateNumber(@RequestBody ShoppingCart shoppingCart) {
        return shoppingCartService.updateNumber(shoppingCart);
    }

    @RequiresLogin
    @RequestMapping("/del")
    public RestResult del(@RequestBody int[] ids) {
        return shoppingCartService.del(ids);
    }

    @RequiresLogin
    @RequestMapping("/ids")
    public RestResult selectByIds(@RequestBody int[] ids) {
        return shoppingCartService.selectByIds(ids);
    }

    @RequiresLogin
    @RequestMapping("/size")
    public RestResult size(@RequestHeader("authorization") String authorization) {
        return shoppingCartService.size(authorization);
    }
}
